package me.zhengjie.modules.rest.enterprise;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.domain.enterprise.EnterpriseInvestment;
import me.zhengjie.modules.service.EnterpriseInvService;
import me.zhengjie.modules.utils.Contents;
import me.zhengjie.modules.utils.JsonUtils;
import me.zhengjie.modules.utils.ReturnObject;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Api("企业投资动态api")
@RestController
@RequiredArgsConstructor
@RequestMapping("/enterInv")
public class EnterpriseInvController {

    private final EnterpriseInvService enterpriseInvService;

    @ApiOperation("根据企业名称查询投资动态信息")
    @AnonymousAccess
    @GetMapping("/queryEnterpriseInvByName")
    public List<EnterpriseInvestment> queryEnterpriseInvByName(String name){
        return enterpriseInvService.queryEnterpriseInvByName(name);
    }

    @ApiOperation("根据条件分页查询投资动态信息")
    @AnonymousAccess
    @GetMapping("/queryEnterpriseInvForPageByConditions")
    public Map<String,Object> queryEnterpriseInvForPageByConditions(String year,String round,@RequestParam Integer pageNo,@RequestParam Integer pageSize){
        Map<String,Object> map=new HashMap<>();
        if(round!=null&&round.equals("")){
            round=null;
        }
        if(year!=null&&year.equals("")){
            System.out.println(year);
            year=null;
        }
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("year",year);
        map.put("round",round);
        List<EnterpriseInvestment> list=enterpriseInvService.queryEnterpriseInvForPageByConditions(map);
        int total=enterpriseInvService.queryEnterpriseInvForPageByConditionsToTotal(map);
        map=new HashMap<>();
        map.put("list",list);
        map.put("total",total);
        return map;
    }
}
